package ar.edu.itba.pod.Legajo47342.communication.handlers;

import java.rmi.RemoteException;

import ar.edu.itba.pod.Legajo47342.Node;
import ar.edu.itba.pod.Legajo47342.communication.payload.NodeAgentLoadPayloadImpl;
import ar.edu.itba.pod.simul.communication.Message;
import ar.edu.itba.pod.simul.communication.MessageType;
import ar.edu.itba.pod.simul.communication.NodeAgentLoad;
import ar.edu.itba.pod.simul.communication.payload.Payload;

public class NodeAgentLoadRequestHandler implements Handler {

private Node node;
	
	public NodeAgentLoadRequestHandler(Node node) {
		super();
		this.node = node;
	}
	
	@Override
	public void handle(Message message) {
		Message m;
		Payload p;
		System.out.println("TENGO: "+node.getSimulManager().getAgents().size());
		p = new NodeAgentLoadPayloadImpl(new NodeAgentLoad(node.getNodeId(), node.getSimulManager().getAgents().size()));
		m = new Message(node.getNodeId(), System.currentTimeMillis(), MessageType.NODE_AGENTS_LOAD, p);
		try {
			node.getManager().getGroupCommunication().send(m, message.getNodeId());
		} catch (RemoteException e) {
			e.printStackTrace();
		}

	}

}
